import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";
const { createMessage: $message } = useMessage();

enum Api {
  treeGrid = '/customer/treeGrid',
  get = '/customer/queryById',
  delete = '/customer/delete',
  asyncZtreeNode = '/customer/asyncZtreeNode',
  save = '/customer/save',
  saveCity = '/customer/saveCity',
  saveDirectory = '/customer/saveDirectory',
  updateBatchOrders = '/customer/updateBatchOrders',
  //2023-07-23
  departSelect = '/customer/depart/regeionSelect',
  departList = '/customer/depart/list',
  departSave = '/customer/depart/save',
  departDelete = '/customer/depart/delete',
  departById = '/customer/depart/queryById',
}

export enum TypeEnum {
  CITE = '0',
  COMP = '1',
  PERS = '2',
}

/**
 * 列表接口
 * @param params
 */
export const treeGrid = async (params) => await defHttp.get({url: Api.treeGrid, params});

/**
 * 删除菜单
 */
export const deleteCustomer = (params,handleSuccess) => {
  return defHttp.delete({
    url: Api.delete,
    params
  }, { joinParamsToUrl: true, isTransformResponse: false }).then((res) => {
    if (res.success) {
      $message.success(res.message)
      handleSuccess()
    } else {
      $message.error(res.message)
    }
  });
}

/**
 * 删除菜单
 */
export const asyncZtreeNode1 = async (params) => {
  let result = await defHttp.get({url: Api.asyncZtreeNode, params});
  return result.map(item => {
    if (item.hasChildren === 'true') {
      return { ...item, children: [] }
    } else {
      return item
    }
  })
}

/**
 * 供应商 - 客户树
 * @param params
 */
export const asyncZtreeNode = (params) => defHttp.get({url: Api.asyncZtreeNode, params}, {joinParamsToUrl: true});


/**
 * 查询详情
 * @param params
 */
export const getCustomerById = (params) => {
  return defHttp.get({ url: Api.get, params });
}

/**
 * 保存或者更新菜单
 * @param params
 */
export const customerSave = (url, params) => {
  return defHttp.post({ url: url, params });
}

/**
 * 查询详情
 * @param params
 */
export const updateBatchOrders = () => {
  return defHttp.get({ url: Api.updateBatchOrders });
}

//-------------2023-08-01--------qindl------------------------------------------------------------------------
/**
 * 供应商 - 部门 - 树
 * @param params
 */
export const departSelect = (params) => defHttp.get({url: Api.departSelect, params}, { isTransformResponse: false });

/**
 * 供应商 - 部门 - 列表
 * @param params
 */
export const departList = async (params) => await defHttp.get({url: Api.departList, params});

/**
 * 保存或者更新菜单
 * @param params
 */
export const departSave = (params) => {
  return defHttp.post({ url: Api.departSave, params });
}

/**
 * 供应商 - 部门 - 删除
 * @param params
 */
export const departById = (params) => {
  return defHttp.get({ url: Api.departById, params });
}

/**
* 供应商 - 部门 - 删除
*/
export const departDelete = (params,handleSuccess) => {
  return defHttp.delete({
    url: Api.departDelete,
    params
  }, { joinParamsToUrl: true, isTransformResponse: false }).then((res) => {
    if (res.success) {
      $message.success(res.message)
      handleSuccess()
    } else {
      $message.error(res.message)
    }
  });
}